package user

import (
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"google.golang.org/grpc/resolver"
	"log"
	"test.com/project-api/config"
	"test.com/project-common/discovery"
	"test.com/project-common/logs"
	login "test.com/project-grpc/user/login"
)

var LoginServiceClient login.LoginServiceClient

// InitRpcUserClient
//
//	@Description: 创建上面的user服务对象
func InitRpcUserClient() {
	//调用discovery.NewResolver(etcd地址, 日志对象), 返回etcdRegister
	etcdRegister := discovery.NewResolver(config.C().EtcdConfig.Addrs, logs.LG)

	//将注册信息注册给resolver
	resolver.Register(etcdRegister)

	//呼叫本机etcd的user服务
	conn, err := grpc.Dial("etcd:///user", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	//根据连接创建user服务的对象
	LoginServiceClient = login.NewLoginServiceClient(conn)
}
